<%--
  Created by IntelliJ IDEA.
  User: dengdc
  Date: 2017/7/19
  Time: 17:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<html>
<head>
    <title>diyishou </title>
    <jsp:include page="../../head.jsp"/>
    <script type="text/javascript">
        //
        <!--业务编码、集装箱号、合同协议号、提运单号、进出口类型、收发货人、供应商、下单人-->
        var formSetting = {
            title: "查询信息",
            module: 'query',
            columns: [
                {
                    name: "customerName",
                    label: "客户名称"
                }, {
                    name: "companyType",
                    label: "公司类型",
                    type: "dropdown",
                    dropdownType: "ajax",
                    keyWordName: 'key',
                    url: "/order-dropdown/getCompanyType",
                    minLength: 0,
                    success: function (data) {
                        data = data.results;
                        var array = [];
                        $.each(data, function (i, n) {
                            array.push([n["name"], n["value"]]);
                        });
                        return array;
                    }
                },
                {
                    name: "status",
                    label: "状态",
                    type: "dropdown",
                    data: [["草稿", "0"], ["待生效", "1"],["生效", "2"],["结束", "3"]]
                },
                {
                    name: "eftTimeBegin",
                    label: "生效时间起",
                    type: 'date',
                    validate: 'validate[required]'
                },
                {
                    name: "eftTimeEnd",
                    label: "生效时间止",
                    type: 'date',
                    validate: 'validate[required]'
                },{
                    name: "feeName",
                    label: "费用名称"
                },
                {
                    name: "chargeMode",
                    label: "费用规则",
                    type: "dropdown",
                    dropdownType: "ajax",
                    url: "/order-dropdown/getChargeMode",
                    minLength: 0,
                    success: function (data) {
                        data = data.results;
                        var array = [];
                        $.each(data, function (i, n) {
                            array.push([n["name"], n["value"]]);
                        });
                        return array;
                    }
                },
                {
                    name: "supplierName",
                    label: "报关行"
                }
                ],
            buttons: {
                custom: [
                    {
                        id: "updatebtn2",
                        value: "新增",
                        click: function () {
                            add();
                        }
                    },
                    {
                        id: "updatebtn3",
                        value: "修改",
                        click: function () {
                            modify();
                        }
                    },
                    {
                        id: "updatebtn4",
                        value: "删除",
                        click: function () {
                            del();
                        }
                    },
                    {
                        id: "updatebtn5",
                        value: "状态确认",
                        click: function () {
                            confStatus();
                        }
                    }
                ]
            },
            grid: {
                id: "tgrid",
                title: "查询结果",
                url: "/platformFee/getListData",
                colModel: [
                    {
                        label: '主键',
                        index: "id",
                        name: "id",
                        key: true
                    },
                    {label: '公司类型', name: 'companyTypeChn', index: 'companyTypeChn'},
                    {label: '客户名称', name: 'customerName', index: 'customerName'},
                    {label: '是否委托自己', name: 'agentSelfChn', index: 'agentSelfChn'},
                    {label: '费用名称', name: 'feeName', index: 'feeName'},
                    {label: '计费规则', name: 'chargeModeChn', index: 'chargeModeChn'},
                    {label: '报关行', name: 'supplierName', index: 'supplierName'},
                    {label: '费用值', name: 'feeAmount', index: 'feeAmount'},
                    {label: '生效时间从', name: 'eftTimeBegin', index: 'eftTimeBegin'},
                    {label: '生效时间至', name: 'eftTimeEnd', index: 'eftTimeEnd'},
                    {label: '状态', name: 'status', index: 'status',
                        formatter: function (value, options, row) {
                            if (value == "0") {//隐性客户
                                return "草稿";
                            } else if (value == "1") {//混合型客户
                                return "待生效";
                            } else if(value == "2"){//根据逻辑判断
                                return "生效";
                            }else if(value == "3"){//根据逻辑判断
                                return "结束";
                            }else {
                                return "未知状态";
                            }
                        }
                    }
                ],
                multiselect: true
            }
        };
        $(document).ready(function () {
            $("#table").mrdForm(formSetting);
            doResize();
            $(window).resize(function () {
                doResize();
            });

            $(".ui-jqgrid-title").text("客户信息列表");
        });

        function doResize() {
            var ss = getPageSize();
            $("#tgrid").jqGrid('setGridHeight', ss.WinH - 310);
        }

        function getPageSize() {
            var winW, winH;
            if (window.innerHeight) {// all except IE
                winW = window.innerWidth;
                winH = window.innerHeight;
            } else if (document.documentElement && document.documentElement.clientHeight) {// IE 6 Strict Mode
                winW = document.documentElement.clientWidth;
                winH = document.documentElement.clientHeight;
            } else if (document.body) { // other
                winW = document.body.clientWidth;
                winH = document.body.clientHeight;
            }
            return {WinW: winW, WinH: winH};
        }

        //选择多条记录
        function getSels(gridId) {
            var grid = $("#" + gridId);
            var rowKey = grid.getGridParam("selrow");
            if (!rowKey) {
                alert("请选择一条记录");
                return;
            }

            return grid.getGridParam("selarrrow");
        }

        //选择一条记录
        function getSelectedRowById(gridId) {
            var grid = $("#" + gridId);
            var rowKey = grid.getGridParam("selrow");
            if (!rowKey) {
                alert("请选择一条记录");
                return;
            }

            var selectedIDs = grid.getGridParam("selarrrow");
            if (selectedIDs.length > 1) {
                alert("只能选择一条记录");
                return;
            }

            return selectedIDs[0];
        }

        /**
         * 删除
         * @author han
         */
        function del(){
            var ids = getSels("tgrid");
            if (ids == null) {
                return;
            }

            $.ajax({
                type: "POST",
                url: "/platformFee/delFlagBatch",
                contentType: "application/json",
                data: JSON.stringify(ids),
                success: function (r) {
                    if (r.error_code == 0) {
                        layer.alert("删除成功");
                        $("#tGrid").trigger("reloadGrid");
                    } else {
                        layer.alert(r.msg);
                    }
                }
            });
        }

        /**
         * 修改
         * @author han
         */
        function modify() {
            var id = getSelectedRowById('tgrid');
            if (id == null) {
                return;
            }
            var row = $("#tgrid").getRowData(id);

            window.location.href = "editPage?id="+row.id;
        }

        /**
         * 新增
         * @author han
         */
        function add(){
            window.location.href = "editPage";
        }

        /**
         * 状态确认
         * @author han
         */
        function confStatus(){
            var id = getSelectedRowById('tgrid');
            if (id == null) {
                return;
            }
            var row = $("#tgrid").getRowData(id);
            if(row.status=="草稿"){
                var param = {};
                param.id = row.id;
                var url = "/platformFee/confStatus";

                $.ajax({
                    type: "POST",
                    url: url,
                    data: param,
                    success: function (r) {
                        if (r.error_code == 0) {
                            $("#tgrid").trigger("reloadGrid");
                        } else {
                            layer.alert(r.msg);
                        }
                        layer.closeAll();
                    }
                });
            }else{
                layer.alert("草稿状态才能确认为生效状态");
            }
        }


    </script>
</head>
<body>
<div id="table"></div>
</body>
</html>
